import os

class Action(object):
  def execute(self):
    raise NotImplementedError

class DeleteFile(Action):
  def __init__(self, target):
    self.target = target

  def __repr__(self):
    return "Delete: %s" % self.target

  def execute(self):
    os.remove(self.target)

class MakeDirectory(Action):
  def __init__(self, target, mode = 0755):
    self.target = target
    self.mode = mode

  def __repr__(self):
    return "Make Directory: %s" % self.target

  def execute(self):
      os.mkdir(self.target, self.mode)

class MoveFile(Action): 
  def __init__(self, src, dst):
    self.src = src
    self.dst = dst

  def __repr__(self):
    if os.path.exists(self.dst):
      return "Move: %s to %s (overwrite)" % (self.src, self.dst)
    else:
      return "Move: %s to %s" % (self.src, self.dst)

  def execute(self):
    folder, filename = os.path.split(self.dst)
    if not os.path.exists(folder):
      return [MakeDirectory(folder), self]
    elif os.path.exists(self.dst):
      return [DeleteFile(self.dst), self]
    else:
      os.rename(self.src, self.dst)
      return

